#include "smileyanimationemotionmanager.h"
#include "smileyanimationemotionconstants.h"
#include "smileyanimationemotion.h"
#include "abstractemotion.h"
#include "utils/emotionutility.h"

#include <QPixmap>


namespace Emotion {

SmileyAnimationEmotionManager *SmileyAnimationEmotionManager::m_instance = NULL;

SmileyAnimationEmotionManager::SmileyAnimationEmotionManager(QObject *parent) :
    AbstractEmotionManager(parent)
{
    init();
}


SmileyAnimationEmotionManager::~SmileyAnimationEmotionManager()
{
    m_instance = NULL;
}


SmileyAnimationEmotionManager *SmileyAnimationEmotionManager::instance(QObject *parent)
{
    if (!m_instance)
        m_instance = new SmileyAnimationEmotionManager(parent);
    return m_instance;
}


void SmileyAnimationEmotionManager::init()
{
    loadEmotion();
}


AbstractEmotionManager::EmotionManagerType
SmileyAnimationEmotionManager::type() const
{
    return AbstractEmotionManager::SmileyAnimationManagerType;
}


int SmileyAnimationEmotionManager::count() const
{
    return SMILEY_ANIMATION_EMOTION_COUNT;
}


AbstractEmotion *SmileyAnimationEmotionManager::createEmotion(int index) const
{
    if ((index < 1) || (index > count()))
        return NULL;

    QString name = genName(index);
    QString code = getCode(index);
    QString meaning = getMeaning(index);
    QString fullPath;
    if (index < 77) {
        fullPath = Utility::EmotionUtility::smileyAnimationEmotionPath() + "/" + name + ".gif";
    } else {
        fullPath = Utility::EmotionUtility::smileyAnimationEmotionPath() + "/" + name + ".jpg";
    }

    QSize size = QPixmap(fullPath).size();

    SmileyAnimationEmotion *emotion = new SmileyAnimationEmotion(name, meaning, code, fullPath);
    emotion->setSize(size);

    return emotion;
}


QString SmileyAnimationEmotionManager::genName(int index) const
{
    return QString(SMILEY_ANIMATION_EMOTION_NAME) + "-" + QString::number(index);
}


QString SmileyAnimationEmotionManager::getCode(int index) const
{
    switch (index) {
    case 1:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_1);
    case 2:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_2);
    case 3:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_3);
    case 4:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_4);
    case 5:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_5);
    case 6:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_6);
    case 7:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_7);
    case 8:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_8);
    case 9:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_9);
    case 10:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_10);
    case 11:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_11);
    case 12:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_12);
    case 13:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_13);
    case 14:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_14);
    case 15:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_15);
    case 16:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_16);
    case 17:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_17);
    case 18:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_18);
    case 19:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_19);
    case 20:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_20);
    case 21:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_21);
    case 22:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_22);
    case 23:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_23);
    case 24:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_24);
    case 25:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_25);
    case 26:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_26);
    case 27:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_27);
    case 28:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_28);
    case 29:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_29);
    case 30:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_30);
    case 31:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_31);
    case 32:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_32);
    case 33:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_33);
    case 34:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_34);
    case 35:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_35);
    case 36:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_36);
    case 37:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_37);
    case 38:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_38);
    case 39:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_39);
    case 40:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_40);
    case 41:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_41);
    case 42:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_42);
    case 43:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_43);
    case 44:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_44);
    case 45:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_45);
    case 46:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_46);
    case 47:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_47);
    case 48:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_48);
    case 49:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_49);
    case 50:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_50);
    case 51:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_51);
    case 52:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_52);
    case 53:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_53);
    case 54:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_54);
    case 55:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_55);
    case 56:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_56);
    case 57:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_57);
    case 58:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_58);
    case 59:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_59);
    case 60:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_60);
    case 61:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_61);
    case 62:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_62);
    case 63:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_63);
    case 64:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_64);
    case 65:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_65);
    case 66:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_66);
    case 67:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_67);
    case 68:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_68);
    case 69:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_69);
    case 70:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_70);
    case 71:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_71);
    case 72:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_72);
    case 73:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_73);
    case 74:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_74);
    case 75:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_75);
    case 76:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_76);
    case 77:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_77);
    case 78:
        return QString(SMILEY_ANIMATION_EMOTION_CODE_78);

    default:
        return QString();
    }
}


QString SmileyAnimationEmotionManager::getMeaning(int index) const
{
    switch (index) {
    case 1:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_1);
    case 2:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_2);
    case 3:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_3);
    case 4:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_4);
    case 5:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_5);
    case 6:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_6);
    case 7:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_7);
    case 8:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_8);
    case 9:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_9);
    case 10:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_10);
    case 11:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_11);
    case 12:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_12);
    case 13:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_13);
    case 14:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_14);
    case 15:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_15);
    case 16:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_16);
    case 17:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_17);
    case 18:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_18);
    case 19:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_19);
    case 20:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_20);
    case 21:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_21);
    case 22:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_22);
    case 23:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_23);
    case 24:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_24);
    case 25:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_25);
    case 26:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_26);
    case 27:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_27);
    case 28:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_28);
    case 29:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_29);
    case 30:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_30);
    case 31:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_31);
    case 32:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_32);
    case 33:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_33);
    case 34:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_34);
    case 35:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_35);
    case 36:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_36);
    case 37:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_37);
    case 38:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_38);
    case 39:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_39);
    case 40:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_40);
    case 41:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_41);
    case 42:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_42);
    case 43:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_43);
    case 44:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_44);
    case 45:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_45);
    case 46:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_46);
    case 47:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_47);
    case 48:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_48);
    case 49:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_49);
    case 50:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_50);
    case 51:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_51);
    case 52:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_52);
    case 53:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_53);
    case 54:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_54);
    case 55:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_55);
    case 56:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_56);
    case 57:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_57);
    case 58:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_58);
    case 59:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_59);
    case 60:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_60);
    case 61:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_61);
    case 62:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_62);
    case 63:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_63);
    case 64:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_64);
    case 65:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_65);
    case 66:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_66);
    case 67:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_67);
    case 68:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_68);
    case 69:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_69);
    case 70:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_70);
    case 71:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_71);
    case 72:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_72);
    case 73:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_73);
    case 74:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_74);
    case 75:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_75);
    case 76:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_76);
    case 77:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_77);
    case 78:
        return QString(SMILEY_ANIMATION_EMOTION_MEANING_78);

    default:
        return QString();
    }
}

} // namespace Emotion
